/**
 * create by ck on 2016/3/7.
 */
var resPackIds;
var appCode;
var inList;
var outList;
$(document).ready(function() {
    appCode  = xhTool.getQuery('iAppCode');
    var DataGrid2 = new DataGridEvent();
    inList = $('#InList');
    outList = $('#OutList');
    inList.initDataGrid(baseUrl + 'Res/getContactRPack', {"queryParams": {"iAppCode": appCode,"type": "in"}})
        .setSelectThenEnable(['bt_out'], [], 'bs');
    outList.initDataGrid(baseUrl + 'Res/getContactRPack', {"queryParams": {"iAppCode": appCode,"type": "out"}}, DataGrid2)
        .setSelectThenEnable(['bt_in'], [], 'bs', DataGrid2);
    $('#bt_in').click(function(){
        resPackIds = outList.getDataGridSelectedFields('iRPId');  //获取所选行未关联题库ID
        contactQuestion('in');
    });
    $('#bt_out').click(function(){
        resPackIds = inList.getDataGridSelectedFields('iRPId');   //获取所选行已关联题库ID
        contactQuestion('out');
    });
});
//根据类型进行关联或取消关联操作
function contactQuestion(type) {
    $.post(baseUrl + 'Res/contactAppResPack', {iAppCode: appCode, resPackIds: resPackIds, type: type}, function (result) {
        $('body').append(result);
        inList.dataGridReload();
        outList.dataGridReload();
        $('#bt_in, #bt_out').setButtonDisable('bs');
    });
}